﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using VietPremier.Repository;

namespace VietPremier
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            #region Promotion
            routes.MapRoute(
               name: "Promotion",
               url: "khuyen-mai",
               defaults: new { controller = "Promotion", action = "Index" },
               constraints: new { customConstraint = new PromotionRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );

            routes.MapRoute(
               name: "PromotionDetail",
               url: "khuyen-mai/{title}",
               defaults: new { controller = "Promotion", action = "Detail", title = UrlParameter.Optional },
               constraints: new { customConstraint = new DetailPromotionRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelHotel
            routes.MapRoute(
               name: "TravelHotel",
               url: "san-pham-du-lich/khach-san-khu-resort",
               defaults: new { controller = "TravelInformation", action = "Hotel" },
               constraints: new { customConstraint = new TravelHotelRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region InquiryNow
            routes.MapRoute(
               name: "InquiryNow",
               url: "dat-tour",
               defaults: new { controller = "Inquiry", action = "Index" },
               constraints: new { customConstraint = new InquiryNowRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region AboutUs
            routes.MapRoute(
               name: "AboutUse",
               url: "gioi-thieu",
               defaults: new { controller = "AboutUs", action = "Index" },
               constraints: new { customConstraint = new AboutUsRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelInformation
            routes.MapRoute(
               name: "TravelInformation",
               url: "san-pham-du-lich",
               defaults: new { controller = "TravelInformation", action = "Information" },
               constraints: new { customConstraint = new TravelInformationRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelCountry
            routes.MapRoute(
               name: "TravelProduct",
               url: "san-pham-du-lich/{title}",
               defaults: new { controller = "TravelInformation", action = "Product", title = UrlParameter.Optional },
               constraints: new { customConstraint = new TravelProductRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelCity
            routes.MapRoute(
               name: "TravelCity",
               url: "san-pham-du-lich/{country}/{title}",
               defaults: new { controller = "TravelInformation", action = "City", title = UrlParameter.Optional, country = UrlParameter.Optional },
               constraints: new { customConstraint = new TravelCityRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelStyle
            routes.MapRoute(
               name: "TravelStyle",
               url: "phong-cach-du-lịch/{title}",
               defaults: new { controller = "Style", action = "TravelStyle", title = UrlParameter.Optional},
               constraints: new { customConstraint = new TravelStyleRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region TravelDetail
            routes.MapRoute(
               name: "TravelDetail",
               url: "phong-cach-du-lịch/{title}/{city}",
               defaults: new { controller = "Style", action = "TravelDetail", title = UrlParameter.Optional, city = UrlParameter.Optional },
               constraints: new { customConstraint = new TravelStyleDetailRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region IndexDestination
            routes.MapRoute(
               name: "IndexDestination",
               url: "thong-tin-du-lich",
               defaults: new { controller = "Destination", action = "Index" },
               constraints: new { customConstraint = new IndexDestinationRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region DestinationCountryList
            routes.MapRoute(
               name: "DestinationCountryList",
               url: "thong-tin-du-lich/{title}",
               defaults: new { controller = "Destination", action = "DestinationCountryList", title = UrlParameter.Optional },
               constraints: new { customConstraint = new DestinationCountryListRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region Destination
            routes.MapRoute(
               name: "Destination",
               url: "thong-tin-du-lich/{name}/{title}",
               defaults: new { controller = "Destination", action = "Destination", title = UrlParameter.Optional, name = UrlParameter.Optional },
               constraints: new { customConstraint = new DestinationRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region DestinationDetail
            routes.MapRoute(
               name: "DestinationDetail",
               url: "thong-tin-du-lich/{name}/{title}/{destination}",
               defaults: new { controller = "Destination", action = "DestinationDetail", title = UrlParameter.Optional, name = UrlParameter.Optional, destination = UrlParameter.Optional },
               constraints: new { customConstraint = new DestinationDetailRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            #region News_EventDetail
            routes.MapRoute(
               name: "News_EventDetail",
               url: "tin-tuc-su-kien/{title}",
               defaults: new { controller = "Home", action = "News_EventDetail", title = UrlParameter.Optional },
               constraints: new { customConstraint = new News_EventDetailRouteConstraint() },
               namespaces: new[] { "VietPremier.Controllers" }
           );
            #endregion

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}